package Admin

import (
	"FromNowOnPromote/博客系统/Tblog/models"
	"FromNowOnPromote/博客系统/Tblog/models/User"
	"log"
)

type TbAdmin struct {
	AUuid    int    `gorm:"AUTO_INCREMENT;PRIMARY_KEY"` //管理员账号
	UserId   string `gorm:"type:varchar(255);not null"`
	Username string `gorm:"type:varchar(255);not null"` //用户名
	Password string `gorm:"type:varchar(255);not null"` //密码

	//外键关联
	User []User.TbUser `gorm:"FOREIGNKEY:Uuid;ASSOCIATION_FOREIGNKEY:AUuid"`
}

//设置表名
func (TbAdmin) TableName() string {
	return "tbadmin"
}

func init() {
	db := models.ConnDb()
	//判断表是否存在
	bl := db.HasTable(&TbAdmin{})
	if bl == false {
		db.CreateTable(&TbAdmin{})
	} else {
		err := db.AutoMigrate(&TbAdmin{}).Error
		if err != nil {
			log.Fatal(err)
		}
	}
}
